<template>
    <div class="login">
      <el-card class="card">
        <div slot="header">
          <span style="font-size: 20px;font-weight: bold">教师登录</span>
        </div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="工号">
            <el-input v-model="form.code"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input type="password" v-model="form.password"></el-input>
          </el-form-item>
          <div style="margin-left: 40%">
            <el-button type="success" style="width: 100px" @click="login">登录</el-button>
          </div>
        </el-form>
      </el-card>
    </div>
</template>

<script>
  import {login} from "../api/teacher";
  import {mapGetters} from "vuex"
  import {mixin} from "../mixins";

  export default {
    name: "Login",
    mixins: [mixin],
    computed:{
        ...mapGetters([
          'teacherId',
          'img',
          'teacherName'
        ])
    },
    data(){
        return{
          form: {
            num: '',
            password: ''
          }
        }
    },
    methods:{
      login(){
        login(this.form.code, this.form.password).then(({data}) => {
          if(data.code === 0){
            this.$store.commit("setTeacherId", data.teacher.id);
            this.$store.commit("setImg", 'https://gulimall-xiaochun.oss-cn-beijing.aliyuncs.com/img/%E5%A4%B4%E5%83%8F-%E7%94%B7%E5%85%AD.png');
            this.$store.commit("setTeacherName", data.teacher.name);
            this.$store.commit("setLoginIn", true);
            this.$router.push({path: '/teacher'})
            this.notify("登录成功", "success");
          }else{
            this.notify("账号或密码不正确", "error");
          }
        }).catch(err => {
          console.error(err)
        })
      }
    }
  }
</script>
<style>
  .login{
    background-image: url("../assets/login/login1.jpg");
    position:absolute;
    left:0;
    width: 100%;
    height: 100%;
    right:0;
    bottom:0;
    top:0;
  }
  .card{
    position:absolute;
    left: 10%;
    top: 50%;
    width: 30%;
  }
</style>

